package com.maxd.controller;

import com.maxd.bean.PageRes;
import com.maxd.error.Result;
import com.maxd.error.ResultUtil;
import com.maxd.model.OrderPartnerInfo;
import com.maxd.model.StudentInfo;
import com.maxd.service.student.StudentService;
import com.maxd.utils.AdminUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(value="学员管理", tags = {"学员管理"})
@RequestMapping(value = "/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping("/save-student")
    @ApiOperation("内管新增/修改学员信息")
    public Result<Void> studentPage(@RequestBody @Validated StudentInfo studentInfo) {
        AdminUtils.checkLogin();
        studentService.save(studentInfo);
        return ResultUtil.success(null);
    }

    @GetMapping("/student-page")
    @ApiOperation("内管分页查询学员列表")
    public Result<PageRes<StudentInfo>> studentPage(@ApiParam("页码，从0页开始") @RequestParam("pageNo") Integer pageNo,
                                                    @ApiParam("每页记录数量") @RequestParam("pageSize") Integer pageSize,
                                                    @ApiParam("学员姓名，支持模糊查询") @RequestParam(value = "name", required = false) String name) {
        AdminUtils.checkLogin();
        PageRes<StudentInfo> pageRes = studentService.queryPage(pageNo, pageSize, name);
        return ResultUtil.success(pageRes);
    }

    @GetMapping("/student-list")
    @ApiOperation("内管查询学员列表")
    public Result<List<StudentInfo>> studentList(@ApiParam("学员姓名，支持模糊查询") @RequestParam(value = "name", required = false) String name) {
        AdminUtils.checkLogin();
        List<StudentInfo> studentInfos = studentService.queryList(name);
        return ResultUtil.success(studentInfos);
    }

}
